#pragma once
#include "MessageReactor.h"
#if (COMM_FEATURE_LIBEVENT==1)

namespace COMM
{
	class COMM_API MessageFilter
	{
	public:
		virtual ~MessageFilter(){}
		virtual void Release(){ delete this;}
		virtual void OnOpen(MessageHandler* hanlder){}
		// reason: CONN_EOF(peer shutdown),CONN_ERR(connection error),CONN_SHUTDOWN(close by manual).
		virtual void OnClose(MessageHandler* hanlder, SocketClient::ConnectionState reason){}
		// return true mean the message had handled, would not be route to other filters. 
		virtual bool OnMessage(MessageHandler* hanlder, const char* buffer, int size){ return false;}	
	};

#ifdef COMM_MSVC
	template class COMM_API stdlist<MessageFilter*>;
	template class COMM_API List<MessageFilter*>;
#endif

	class COMM_API MessageFilterManager : public MessageHandler
	{
	public:
		MessageFilterManager(List<MessageFilter*>* filterList);
		~MessageFilterManager();
		virtual void OnOpen();
		// reason: CONN_EOF(peer shutdown),CONN_ERR(connection error),CONN_SHUTDOWN(close by manual).
		virtual void OnClose(SocketClient::ConnectionState reason);
		virtual void OnMessage(const char* buffer, int size);

	private:
		List<MessageFilter*>* m_filterList;

	};
}

#endif
